<?php

/**
 * This file is part of the Framework03 PHP framework.
 * @author Walter Tamboer
 * @package Framework03
 */

/**
 * This class is able to render JSON pages.
 */
class FW_View_Json extends FW_View_Abstract
{
    /**
     * @var mixed The data used to create the json data.
     */
    private $data;

    /**
     * Initializes a new instance of this class.
     * @param mixed $data Could be anything except resources
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Renders the view to the screen.
     * @param FW_Controller_Action $controller The controller that wants the rendering to be done.
     * @param string $actionName The name of the action that wants the rendering to be done.
     */
    public function render(FW_Controller_Action $controller, $actionName)
    {
		if (is_resource($this->data))
			throw new Exception('Resources cannot be encoded to JSON');

		//header('Content-type: text/x-json');
		echo json_encode($this->data);
    }
}
